home *** CD-ROM | disk | FTP | other *** search
/ Quick PC 62 / Quick PC 62.iso / I386 / IIS5_01.CAB / IIS_iijsls.inc < prev    next >
Encoding:
Text File  |  1998-05-29  |  5.1 KB  |  246 lines

  1. <% ' General depository for frequently used javascript functions for our "list control" ******* %>
  2.  
  3. <!--#include file="iijsls.str"-->
  4.  
  5. <%
  6. ' Main listFunction object, to allow other frames to access global functions, 
  7. ' and to serve as a data cache. This will be instantiated in the list script.
  8. %>
  9. function listFuncs(sortby, specSort, mainframe){
  10.     //general
  11.     this.sel = -1;
  12.     this.lastSel = 0;    
  13.     this.bHasList = true;
  14.     this.noupdate = false;
  15.     this.sortAsc = true;
  16.     
  17.     //functions
  18.     this.addItem=addItem;
  19.     this.delItem=delItem;
  20.     this.moveItem=moveItem;
  21.     this.sortList = sortList;
  22.     this.reSort = reSort;                
  23.     this.writeList=buildListForm;
  24.     this.SetListVals=SetListVals;
  25.     this.writeCol = writeCol;
  26.     this.loadList = loadList;
  27.     
  28.     //specifics
  29.     this.sortby = sortby;
  30.     this.specSort =specSort;        
  31.     this.mainframe = mainframe;
  32. }
  33.  
  34. <% ' ******* Sets the current selection ******* %>
  35.     
  36.     function setLastSel(id)
  37.     {
  38.         for (var i=0; i < cachedList.length; i++)
  39.         {
  40.             if (cachedList[i].id == id)
  41.             {
  42.                 listFunc.sel = i;
  43.                 return;
  44.             }
  45.         }
  46.     }
  47.  
  48. <% ' ******* Used throughout the list "controls" to write out a table cell. ******* %>
  49. <% ' ******* a, the align parameter, is optional ******* %>
  50.         
  51.     function writeCol(colspan,w,str,a)
  52.     {
  53.         var writestr = "<TD";
  54.         if (colspan != "")
  55.         {
  56.             writestr += " COLSPAN = " + colspan
  57.         }
  58.         if (w != "")
  59.         {
  60.             writestr += " WIDTH = " + w;
  61.         }
  62.         if (a != "")
  63.         {
  64.             writestr += " ALIGN = " + a;
  65.         }                            
  66.         writestr += "><%= sFont("","","",True) %>" + str + "</FONT></TD>";
  67.  
  68.         return writestr;    
  69.     }    
  70.     
  71. <% '***** This is the sortOrder function that allows heading to be sorted by string values, rather than numerically... **** %>
  72.     function sortOrder(a,b)
  73.         {
  74.         <%
  75.             ' a and b are automatically passed in by the JScript array sort function
  76.             ' In this case, they are array items which contain custom objects. The
  77.             ' listFunc.sortby is set in the call to sortList, which is executed when
  78.             ' the user clicks a heading. The entry points are in the files labled ii*hd.asp 
  79.             ' (ie, iiacsshd.asp, etc.) The sortby property will contain the name of the 
  80.             ' property on the object to sort by, for example filename or date...
  81.             
  82.             'listFunc is required in order for this to work properly...
  83.         %>        
  84.         
  85.         if (listFunc != null)
  86.         {
  87.             if (listFunc.specSort != "")
  88.             {
  89.                 astr = a[listFunc.specSort] + a[listFunc.sortby];
  90.                 bstr = b[listFunc.specSort] + b[listFunc.sortby];
  91.             }
  92.             else
  93.             {
  94.                 astr = a[listFunc.sortby];
  95.                 bstr = b[listFunc.sortby];
  96.             }
  97.             
  98.             if (!isNaN(astr))
  99.             {
  100.                 astr = astr.toString();
  101.                 bstr = bstr.toString();
  102.                 
  103.             }
  104.             
  105.             lcastr = astr.toLowerCase();
  106.             lcbstr = bstr.toLowerCase();
  107.             
  108.             if (lcastr < lcbstr)
  109.             {
  110.                 retval = -1;
  111.             }
  112.             else
  113.             {
  114.                 if (lcastr > lcbstr)
  115.                 {
  116.                     retval =  1;
  117.                 }
  118.                 else
  119.                 {
  120.                     retval =  0;
  121.                 }
  122.             }
  123.             if (!listFunc.sortAsc)
  124.             {
  125.                 retval = retval * -1;
  126.             }
  127.             return retval;                        
  128.         }
  129.     }
  130.             
  131. <% '***** Sort routine called by headings  ***** %>
  132. <% '***** This requires the sortOrder function ***** %>
  133.     function sortList(sortby)
  134.     {        
  135.         if (listFunc != null)
  136.         {        
  137.             i= listFunc.sel;
  138.             if (i != -1)
  139.             {
  140.                 lastsel = cachedList[i].id
  141.             }
  142.  
  143.             if (sortby != listFunc.sortby)
  144.                 {
  145.                 listFunc.sortby = sortby;
  146.                 listFunc.sortAsc = true;
  147.                 }
  148.             else
  149.                 {
  150.                 listFunc.sortAsc = !listFunc.sortAsc;
  151.                 }
  152.     
  153.             var num = parseFloat(cachedList[sortby]);
  154.             if (isNaN(num))
  155.                 {
  156.                 cachedList.sort(sortOrder);
  157.                 }
  158.             else
  159.                 { 
  160.                 cachedList.sort(numOrder);
  161.                 }
  162.                 
  163.             if (i != -1)
  164.             {            
  165.                 setLastSel(lastsel);                
  166.             }
  167.             loadList();
  168.         }
  169.     }
  170.  
  171.  
  172. <% '**** List Resorting function *** %>
  173.     function reSort()
  174.     {
  175.         //set our sortAsc so we aren't just reversing the list...
  176.         listFunc.sortAsc = !listFunc.sortAsc;
  177.         sortList(listFunc.sortby);
  178.     }
  179.  
  180. <% '**** List Delete function *** %>    
  181.         function delItem(){
  182.         
  183.         if (listFunc.sel >= 0)
  184.         {
  185.             listFunc.noupdate = true;        
  186.             i=eval(listFunc.sel);
  187.             
  188.             cachedList[i].deleted=true;
  189.             cachedList[i].updated=true;
  190.              i=i-1;
  191.             
  192.             <% 'run through the list to find the Next non-deleted item %>
  193.             for (var j=i; j >=0; j--) {
  194.                 if (cachedList[j].deleted){
  195.                 }
  196.                 else{
  197.                     break            
  198.                 }
  199.             }    
  200.             listFunc.sel=j;
  201.             loadList();            
  202.         }
  203.         else{
  204.             alert("<%= L_SELECTITEM_TEXT %>");
  205.         }
  206.     }
  207.     
  208. <% '**** List Delete function *** %>        
  209.  
  210.     function initParam(paramVal,defaultVal)
  211.     {
  212.         if (paramVal == null)
  213.         {
  214.             return defaultVal;
  215.         }
  216.         return paramVal;
  217.     }
  218.     
  219.     function addItem()
  220.     {
  221.         var i=cachedList.length;
  222.         listFunc.noupdate = true;        
  223.         cachedList[i]=new listObj(i);
  224.         cachedList[i].newitem=true;
  225.         cachedList[i].updated=true;
  226.         listFunc.sel=i;
  227.         loadList();
  228.     }
  229.     
  230.     function moveItem(dir){
  231.         sel = eval(listFunc.sel);
  232.         if (sel > -1){
  233.             if (!cachedList[sel].deleted){
  234.                 if ((sel + dir >= 0) && (sel + dir < (cachedList.length))){                
  235.                     cachedList[sel].id += dir;
  236.                     cachedList[sel].updated = true;
  237.                     sel += dir;
  238.                     cachedList[sel].id -= dir;
  239.                 
  240.                     listFunc.sel = sel;
  241.                     cachedList.sort(sortOrder);
  242.                     loadList();
  243.                 }
  244.             }
  245.         }
  246.     }